from bs4 import BeautifulSoup

protein_style = """
.cxsw_description {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.cxsw_description table {
    border-collapse: collapse;
    width: 100%;
    margin: 15px 0;
}

.cxsw_description table.cplist td {
    padding: 12px;
    border: 1px solid #ddd;
}

.cplisttitle td {
    background-color: #f5f5f5;
    font-weight: bold;
    color: #333;
}

.cpprice {
    color: #e74c3c;
    font-weight: bold;
}

.all_p_left2word {
    padding: 20px;
    background-color: #f9f9f9;
    border-radius: 5px;
}

.all_p_left2word p {
    margin-bottom: 15px;
}

.cxsw_description strong {
    color: #2c3e50;
    display: block;
    margin: 20px 0 10px;
}

.title_tr td {
    background-color: #f5f5f5;
    font-weight: bold;
}

.cxsw_description img {
    max-width: 100%;
    height: auto;
    margin: 10px 0;
}

.mytab {
    margin-bottom: 30px;
}

.beyotimeProductExt {
    margin-top: 20px;
}
"""


def process_des(html):
    # 清除空 img 标签
    content = html.replace('<img src=""/>\n', "")
    soup = BeautifulSoup(content, "html.parser")

    # 删除data:image 的img 标签
    img_tag = soup.find("img", src=lambda x: x and x.startswith("data:image"))
    if img_tag:
        img_tag.decompose()

    # 删除旧版广告
    old_ad_tag = soup.find("div", attrs={"id": "con_header"})
    if old_ad_tag:
        old_ad_tag.decompose()
    # 创建新 html
    _description = BeautifulSoup("", "html.parser")
    div_dom = _description.new_tag("div", attrs={"class": "cxsw_description"})

    # 创建样式标签
    style_tag = soup.new_tag("style")
    style_tag.string = protein_style
    div_dom.append(style_tag)
    div_dom.append(soup)

    return str(div_dom)

def process_img(img_list: list) -> list:
    new_list = []
    for _ in range(5):
        new_list.append(img_list[0])
    return new_list